﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace 网络学习记录器
{
    class TxtIO
    {
        public static void TxtWtite(string flna, string i)
        {
            FileStream fs = null;
            StreamWriter sw = null;


            if (!File.Exists(flna))
            {
                fs = File.Create(flna);
                sw = new StreamWriter(fs);
                sw.WriteLine("0");
               
            }
            else
            {
                fs = File.Open(flna, FileMode.Open);
                sw = new StreamWriter(fs);
                sw.WriteLine(i);
                
            }
            sw.Flush();
            sw.Close();
            fs.Close();


        }

        public static string TxtRead(string flna)
        {
            FileStream fs = null;
            StreamWriter sw = null;
            StreamReader sr = null;

            string line = "0";

            if (!File.Exists(flna))
            {
                fs = File.Create(flna);
                sw = new StreamWriter(fs);
                sw.WriteLine("0");
                sw.Flush();
                sw.Close();
            }
            else
            {
                fs = File.Open(flna, FileMode.Open);
                sr = new StreamReader(fs,Encoding.UTF8);
                line = sr.ReadLine();
                sr.Close();
            }
            
            fs.Close();
            
            return line;
        }
    }
}
